package com.xiaoshuidi.cloud.module.contract.controller.admin.contract;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.ContractApplyPageReq;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.ContractApplyPageResp;
import com.xiaoshuidi.cloud.module.contract.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.contract.service.contract.ContractApplyService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * PC-合同申请 续租、退租、延期
 */
@Tag(name = "PC端合同申请")
@RestController
@RequestMapping(ApiConstants.NAME + "/contract-apply")
@Validated
public class ContractApplyController {

    @Resource
    private ContractApplyService contractApplyService;

    /**
     * 申请列表 - 续租、退租、延期
     *
     * @return
     */
    @GetMapping("/page")
    public CommonResult<PageResult<ContractApplyPageResp>> page(@Valid ContractApplyPageReq req) {
        PageResult<ContractApplyPageResp> list = contractApplyService.page(req);
        return CommonResult.success(list);
    }

    /**
     * 审批 - 退租、续租
     *
     * @param id
     * @param flag 通过 true | 驳回 false
     * @return
     */
    @PostMapping("/approve")
    public CommonResult<Boolean> approve(@Valid @NotNull(message = "请选择一个申请") @RequestParam("id") Long id, @NotNull(message = "请选择通过or驳回") @RequestParam("flag") boolean flag) {
        return CommonResult.success(this.contractApplyService.approve(id, flag));
    }
}
